package com.futureway.test.proxy;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.futureway.test.proxy.OrderServiceProxy.OrderServiceProxyFallbackFactory;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

@FeignClient(value = "order-server", fallbackFactory = OrderServiceProxyFallbackFactory.class)
public interface OrderServiceProxy {

	@GetMapping("/order/user/page2")
	@ResponseBody
	public void userPage2();

	@GetMapping("/order/user/page")
	@ResponseBody
	public void userPage(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum);

	// @PostMapping(value = "/order/user/uploadImage", consumes =
	// MediaType.MULTIPART_FORM_DATA_VALUE)
	// public void uploadImage(@RequestPart("file") MultipartFile file);

	@Component
	@Slf4j
	static class OrderServiceProxyFallbackFactory implements FallbackFactory<OrderServiceProxy> {
		@Override
		public OrderServiceProxy create(Throwable cause) {
			return new OrderServiceProxy() {

				@Override
				public void userPage2() {
					log.info(">>>>>>userPage2 fallback;reason was:{}", cause.getMessage());
				}

				@Override
				public void userPage(Integer pageSize, Integer pageNum) {
					log.info(">>>>>>userPage fallback;reason was:{}", cause.getMessage());
				}

			};
		}

	}

}
